{% extends 'basic_app/master.html' %}
{% block tag_left %}
    {% include 'oratk_app/tag_left_user.html' %}
{% endblock %}
{% block title %}
    <title>ORATK</title>
{% endblock %}
{% block userinfo %}


    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
    <h3 class="page-header">定制模板</h3>
        <form name="Form" role="search" action="/oratk_app/oratk_monitor_immediate_new" onsubmit="return validateForm()"
              method="POST">
        <div>
                <label class="col-sm-4 control-label">未添加的实例信息</label>
                <label class="col-sm-5 control-label">已添加的实例信息</label>
        </div>
                    <div class="border">
                        <label class="col-sm-2 control-label" >请选择实例：</label>
                        <select id="ins_leftName" multiple="multiple">
                            {% for i in ins_info %}
                                <option>{{ i.dbname }}__{{ i.conn_string }}</option>
                            {% endfor %}
                        </select>
                        <div id="btn">
                            <input type="button" id="ins_toRight" value="-->"><br>
                            <input type="button" id="ins_toLeft" value="<--">
                        </div>
                        <select id="ins_rightName" multiple="multiple" name="add_ins">
                        </select>
                </div>
          </form>
    </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <div>&nbsp&nbsp&nbsp&nbsp</div>
                <h3 class="page-header">已存在模板</h3>
                <div id="tab_detail" table_count={{ table_count }}></div>

        <table class="table table-striped table-bordered table-hover">
            <thead>
            <tr>
                <th>id</th>
                <th>模板名字</th>
                <th>巡检状态</th>
                <th>巡检报告</th>
                <th>备注</th>
                <th>修改时间</th>
                <th>创建时间</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="tabbody">
            {% for i in current_page %}
                <tr>
                    <td>{{ i.id }}</td>
                    <td>{{ i.name }}</td>
                    <td>{{ i.status }}</td>
                    <td>{{ i.temp_report }}</td>
                    <td>{{ i.remark }}</td>
                    <td>{{ i.chtime }}</td>
                    <td>{{ i.crtime }}</td>
                    <td><a href="/oratk_app/oratk_monitor_template_modify?id={{ i.id }}"
                           target="_blank">禁用</a>
                        <a href="/oratk_app/oratk_monitor_template_modify?id={{ i.id }}"
                           target="_blank">删除</a>
                        <a href="/oratk_app/oratk_monitor_template_modify?id={{ i.id }}"
                           target="_blank">删除</a>
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
        {#        以上是分页#}
        {% include 'basic_app/paginator.html' %}
    </div>
{% endblock %}

{% block script %}
    <script>
        //即时按钮执行前判断输入框是否有空值
        function validateForm() {
            var select_conn = $('#conn_string').find("option:checked").attr("id")
            if (select_conn == 'def') {
                alert('请选择实例')
                return false;
            }
        }

        $(document).ready(function () {
            $('#tabbody tr').each(function (i) {
                var err_list = [];
                $(this).children('td').each(function (j) {
                    //如果状态为error或running ,字体标红
                    if (j == 5) {
                        if ($(this).text() == 'ERROR' || $(this).text() == 'RUNNING') {
                            $(this).css('color', 'red')
                            err_list.push('1')
                        }
                        if ($(this).text() == 'SUCCESS') {
                            $(this).css('color', 'green')
                        }
                    }
                    //如果状态为error或running    1、a标签禁止跳转  2、为自定义属性"err"赋值
                    if (j == 7) {
                        if (err_list.length > 0) {
                            $(this).children('a').attr('href', '#');
                            $(this).children('a').attr('err', 'err');
                            $(this).click(function (event) {
                                event.preventDefault();
                            })


                        }
                    }
                });
            })
        })

        //如果状态为error或running     alter"查询报告不可用"
        function check(which) {
            {#location.reload();#}
            var val = $(which).attr("err")
            if (val == 'err') {
                alert("此条目无法查看报告,请查看巡检详情")
            }
        }

        function refresh() {
            location.reload();
        }
    </script>
{% endblock %}
